*** Setup
clear
use "../data/activity.dta"

** Turn group and country codes into usable non-string codes, make sure
**  they always generate the same codes (depends on order)
sort group
egen groupcode = group(group)
sort country
egen countrycode = group(country)

*** Table 1, plus t-tests

** Codecision
ttest codecisioncount, by(incumbent)
ttest codecisioncount if incumbent | nationalnotincumbent, by(nationalnotincumbent)
* And without De Castro
ttest codecisioncount if incumbent | nationalnotincumbent & mepid != 96891, by(nationalnotincumbent)

** Other report
ttest reportcount, by(incumbent)
ttest reportcount if incumbent | nationalnotincumbent, by(nationalnotincumbent)

** Opinions
ttest opinioncount, by(incumbent)
ttest opinioncount if incumbent | nationalnotincumbent, by(nationalnotincumbent)


** Motions
ttest motioncount, by(incumbent)
ttest motioncount if incumbent | nationalnotincumbent, by(nationalnotincumbent)

** Declarations
ttest declarationcount, by(incumbent)
ttest declarationcount if incumbent | nationalnotincumbent, by(nationalnotincumbent)

** Speeches
ttest speechcount, by(incumbent)
ttest speechcount if incumbent | nationalnotincumbent, by(nationalnotincumbent)

** Questions
ttest questioncount, by(incumbent)
ttest questioncount if incumbent | nationalnotincumbent, by(nationalnotincumbent)

*** Footnote 4
xtset countrycode
xtnbreg codecisioncount incumbent i.groupcode, fe
xtnbreg reportcount incumbent i.groupcode, fe

*** Figure 1
reshape long @count, i(mepid) j(type) string
gen technical=1
replace technical=0 if type=="speech"
replace technical=0 if type=="question"
replace technical=0 if type=="motion"
replace technical=0 if type=="declaration"

graph hbox count if technical, over(incumbent) over(type) asyvars nooutsides
graph hbox count if !technical, over(incumbent) over(type) asyvars nooutsides
